﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class UIEvents_Group1 : MonoBehaviour
{
    public Text UIEdgeText;
    public Text UILenText;
    int sliderValue = 7;
    float outerRadius = 1f;
    public GameObject MapObject;
    public Material MapMaterial;
    public Material CellMaterial;
    public Material UnmovableMaterial;

    public GameObject GroupTwo;

    public void SliderEdgeValueChange(float value)
    {
        sliderValue = Mathf.RoundToInt(value);
        UIEdgeText.text = sliderValue.ToString();
    }
    public void SliderLenValueChange(float value)
    {
        outerRadius = value;
        UILenText.text = value.ToString();
    }
    public void CreateMap()
    {
        //创建地图网格
        Mesh mapMesh = new Mesh();
        MapData mapData = new MapData();
        HexagnoalMapCreator.CreateHexagnoalMapFast(sliderValue, outerRadius, mapData);
        mapMesh.vertices = mapData.Vertices;
        mapMesh.triangles = mapData.Triangles;
        mapMesh.RecalculateBounds();
        mapMesh.RecalculateNormals();
        //创建一个单元格网格
        Mesh cellMesh = new Mesh();
        mapData = new MapData();
        HexagnoalMapCreator.CreateHexagnoalMap(1, outerRadius, mapData);
        cellMesh.vertices = mapData.Vertices;
        cellMesh.triangles = mapData.Triangles;
        cellMesh.RecalculateBounds();
        cellMesh.RecalculateNormals();
        //创建地图数据
        HexagnoalMapData heagonalMapData = new HexagnoalMapData();
        heagonalMapData.CellMesh = cellMesh;
        heagonalMapData.MapMesh = mapMesh;
        heagonalMapData.EdgeCount = sliderValue;
        heagonalMapData.OuterRadius = outerRadius;
        heagonalMapData.MapMaterial = MapMaterial;
        heagonalMapData.CellMaterial = CellMaterial;
        heagonalMapData.UnmovableMaterial = UnmovableMaterial;
        MapObject.SetActive(true);
        MapObject.GetComponent<GetUnMovableCells>().m_MapData = heagonalMapData;
        gameObject.SetActive(false);
        GroupTwo.SetActive(true);
        CameraMove cm = Camera.main.GetComponent<CameraMove>();
        cm.enabled = true;
        cm.speed = Mathf.Max(sliderValue / 3f, 3.5f);
        Vector3 v = Camera.main.transform.position;
        v.y *= outerRadius * sliderValue / Mathf.Min(sliderValue, 10f);
        Camera.main.transform.position = v;
    }
}
